//
//  MineViewController.m
//  Recycling
//
//  Created by jzd on 2018/5/16.
//  Copyright © 2018年 宋佳. All rights reserved.
//

#import "MineViewController.h"
#import "reChargeViewController.h"
#import "AccountSecurityVC.h"
#import "MessageTableViewController.h"
#import "PersonalInfomationVC.h"
#import "transactionTableVC.h"

@interface MineViewController ()
@property (weak, nonatomic) IBOutlet UILabel *BalanceMoney;
@property (weak, nonatomic) IBOutlet UILabel *compeleteNum;
@property (weak, nonatomic) IBOutlet UILabel *owenMoney;
@property (weak, nonatomic) IBOutlet UISwitch *statusSwitch;


@property (strong,nonatomic)NSDictionary *dataDic;
@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BGCOLOR;
    [self setUpNav];
}

-(void)setUpNav{
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithimage:[UIImage imageNamed:@"icon_person"] highImage:nil target:self action:@selector(mineAccountOnClick:) title:@"我的账户"];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"充值" style:UIBarButtonItemStylePlain target:self action:@selector(rechargeOnClick:)];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //实时获取个人工作数据
    [self getWorkInfoMation];
}
-(void)getWorkInfoMation{
    NSDictionary *params = @{@"uid":@([UserInfoTool shareUserInfoTool].Info.ID)};
    [[SJNetWorkTool sharedTool]requestWithURLString:mineWorkInfomation parameters:params method:GET callBack:^(id responseObject, NSError *error) {
        if (responseObject) {
            int code = [[responseObject objectForKey:@"Code"] intValue];
            NSString *msg = [responseObject objectForKey:@"ErrorMessage"];
            id data = [responseObject objectForKey:@"Data"];
            if (code == 1) {
                if (![data isKindOfClass:[NSNull class]]) {
                    CGFloat money = [[data objectForKey:@"Balance"] floatValue];
                    self.BalanceMoney.text = [NSString stringWithFormat:@"%.2f",money];
                    self.compeleteNum.text = [NSString stringWithFormat:@"%d",[[data objectForKey:@"CompleteCount"] intValue]];
                    self.owenMoney.text = [NSString stringWithFormat:@"%.2f",[[data objectForKey:@"TotalMsgAmount"] floatValue]];
                    [self.statusSwitch setOn:[[data objectForKey:@"RecState"] boolValue]];
                }else{
                    [self.navigationController.view showToast:@"空数据" completion:nil];
                }
            }else{
                [self.navigationController.view showToast:msg completion:nil];
            }
            
        }
    }];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    [[SJNetWorkTool sharedTool].tasks makeObjectsPerformSelector:@selector(cancel)];
}
-(void)mineAccountOnClick:(UIBarButtonItem *)item{
    AccountSecurityVC *vc = [[AccountSecurityVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)rechargeOnClick:(UIBarButtonItem *)item{
    reChargeViewController *vc = [[reChargeViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
//更改个人接单状态
- (IBAction)valueChange:(UISwitch *)sender {
    NSInteger num = (sender.isOn)?1:0;
    NSDictionary *params = @{@"uid":@([UserInfoTool shareUserInfoTool].Info.ID),@"state":@(num)};
    [[SJNetWorkTool sharedTool]requestWithURLString:changeAcceptOrderState parameters:params method:POST callBack:^(id responseObject, NSError *error) {
        if (responseObject) {
            int code = [[responseObject objectForKey:@"Code"] intValue];
            if (code == 1) {
                SJLog(@"修改接单状态成功");
            }else{
                SJLog(@"修改接单状态失败");
            }
        }
    }];
    
}
- (IBAction)listOnClick:(UIButton *)sender {
    switch (sender.tag) {
        case 201:{
            SJLog(@"状态");
        }
            break;
        case 202:{
            SJLog(@"个人");
            PersonalInfomationVC *vc = [[PersonalInfomationVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 203:{
            SJLog(@"交易");
            transactionTableVC *vc = [[transactionTableVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 204:{
            SJLog(@"消息");
            MessageTableViewController *vc = [[MessageTableViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}

@end
